package problem77;

import java.util.ArrayList;
import java.util.List;

//77.组合
//https://leetcode.cn/problems/combinations/

class Solution {
    List<List<Integer>> ret = new ArrayList<>();
    List<Integer> path = new ArrayList<>();
    public List<List<Integer>> combine(int n, int k) {
        dfs(n, k, 1);
        return ret;
    }
    public void dfs(int n, int k, int u) {
        if(path.size() == k) {
            ret.add(new ArrayList(path));
            return;
        }

        for(int i = u; i<=n; i++) {
            path.add(i);
            dfs(n, k, i+1);
            path.remove(path.size()-1);
        }
    }
}